use std::fmt::Display;
use std::path::PathBuf;
use clap::Parser;
use serde::Deserialize;

// --- 1. 定义命令行参数 ---
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
    /// 要扫描的路径。可以是一个位置参数，也可以通过 --path 指定。默认为当前目录
    #[arg(long, short, default_value = ".")] // <--- 修改这里
    pub path: PathBuf,

    /// 启用删除模式，否则只进行扫描和报告
    #[arg(long, short, action = clap::ArgAction::SetTrue)] // <-- 推荐的布尔标志用法
    pub delete: bool,
}

// --- 2. 定义项目类型和找到的目标 ---
#[derive(Debug, Clone)]
pub enum ProjectType {
    Cargo,
    Maven,
}

#[derive(Debug, Clone)]
pub struct CleanTarget {
    pub path: PathBuf,
    pub project_type: ProjectType,
    pub size_bytes: u64,
}

#[derive(Debug, Clone)]
pub enum MavenTargetType{
    Target,
    Build,
}

impl ProjectType {
    pub fn tag(&self) -> &'static str {
        match self {
            ProjectType::Cargo => "Cargo.toml",
            ProjectType::Maven => "pom.xml"
        }
    }
}

impl Display for MavenTargetType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let str = match self {
            MavenTargetType::Target => { String::from("target") }
            MavenTargetType::Build => { String::from("build") }
        };
        write!(f, "{}", str)
    }
}

/// <modules> 标签, 它包含一个或多个 <module> 标签
#[derive(Debug, Deserialize, Default)]
pub struct MavenModule {
    #[serde(rename = "module", default)]
    pub module: Vec<String>,
}

/// 代表 pom.xml 的顶层结构 (<project> 标签)
/// 我们只关心 <modules> 部分
#[derive(Debug, Deserialize, Default)]
pub struct MavenPom {
    #[serde(default)]
    pub modules: MavenModule,
}